<style lang="less">
  @import '../styles/common.less';
  @import '../addressBook/index.less';
  @import '../tables/components/table.less';
</style>

<template>
  <div class="address div-relative">
    <Row class="row">
      <Col span="6" class="list-div">
      <Card>
        <p slot="title">
          组织机构
          <!--<span class="list-right">
            <Icon type="ios-git-compare" size="20" title="排序" @click=""></Icon>
          </span>-->
        </p>
        <div class="tree-div user-tree-div user-list-tree-div">
          <Tree :data="TreeData" children-key="children"
                @on-select-change="onTree" :render="renderContent"></Tree>
          <div></div>
        </div>
      </Card>
      </Col>
      <Col span="18" class="padding-left-10 list-div">
      <Card id="TableCard">
        <p slot="title">
          <Icon type="md-people" size="24"></Icon>
          用户列表
          <span v-if="depTitle!=''">（ {{depTitle}} ）</span>
        </p>
        <div class="table-head" v-show="selectionArr.length == 0">
          <div class="left" v-if="is_not_pass != true">
            <Input v-model="search_name" size="default" placeholder="姓名"/>
          </div>
          <div class="left-btn" v-if="is_not_pass != true">
            <Button type="text" icon="ios-search" class="mangerButton4" @click="searchFun()">搜索</Button>
          </div>
          <Button type="primary" class="Button" @click="addUser()">添加</Button>
          <Button type="text" icon="ios-cloud-upload" class="Button" @click="importData()">导入</Button>
          <a href="/vendors/Excel/user.xlsx" download="用户信息.xlsx">
            <Button type="text" icon="ios-document" class="Button">模板</Button>
          </a>
          <Button type="text" icon="ios-cloud-download" class="Button" @click="ExportData()" v-if="data.length > 0">导出
          </Button>
        </div>
        <div class="table-head" v-show="selectionArr.length > 0">
          <div class="left-nums">选中 {{selectionArr.length}} 条 / 共 {{data.length}} 条</div>
          <div class="left-btn">
            <Button type="error" class="Button" @click="removeUser()">删除</Button>
          </div>
          <div class="left-btn">
            <Button type="warning" class="Button" @click="updateFun('update')"
                    :disabled="selectionArr.length == 1 ? false : true">修改
            </Button>
          </div>
          <div class="left-btn">
            <Button type="primary" class="Button" @click="updateFun('updateDep')">调整部门</Button>
          </div>
          <div class="left-btn">
            <Button type="primary" class="Button" @click="ExportData()">导出</Button>
          </div>
          <Button type="text" class="Button" @click="hideNums()">取消</Button>
        </div>
        <Row class="margin-top-10">
          <Table stripe border :columns="columns" :data="data" @on-row-click="onRowData" v-if="is_not_pass != true"
                 @on-selection-change="selectionChange" :height="TableHeight" ref="selectionTable"
                 @on-sort-change="onSortChange"></Table>
          <Table stripe border :columns="columns_not_pass" :data="data_not_pass" @on-row-click=""
                 v-if="is_not_pass == true"
                 @on-selection-change="selectionChange_pass" :height="TableHeight"
                 ref="selectionTable_not_pass"></Table>
          <div style="margin: 10px;overflow: hidden;height: 36px;">
            <div style="float: right;">
              <Page :total="total" :current="page" @on-change="changePage" show-elevator></Page>
            </div>
          </div>
        </Row>
      </Card>
      </Col>
      <!--人员详情-->
      <user-info
        :user_id="userInfo_id"
        @userInfoBackFun="userInfoBackFun"
      ></user-info>
      <!--编辑部门信息-->
      <Modal v-model="dep.showModal" :closable='false' :mask-closable=false :width="600">
        <h3 slot="header" style="color:#2D8CF0">编辑部门信息</h3>
        <Form ref="dep" :model="dep" :label-width="100" label-position="right"
              :rules="addDepValidate">
          <FormItem label="部门类型">
            <Select v-model="dep.type" :transfer="true" style="width:100%;">
              <Option v-for="item in depTypeArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </FormItem>
          <FormItem label="部门名称" prop="name">
            <Input v-model="dep.name" placeholder="请输入部门名称"></Input>
          </FormItem>
          <FormItem label="部门电话">
            <Input v-model="dep.landline" placeholder="请输入部门电话"></Input>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="cancelDepMobile">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="saveDep">保存</Button>
        </div>
      </Modal>
      <!--编辑用户信息-->
      <Modal v-model="addCurrentTableData" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">编辑用户信息</h3>
        <Form label-position="top">
          <FormItem label="姓名">
            <Input v-model="addData.name" placeholder="姓名"></Input>
          </FormItem>
          <FormItem label="性别">
            <Select v-model="addData.sex" :transfer="true" style="width:100%;">
              <Option v-for="item in sexArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </FormItem>
          <FormItem label="岗位" v-if="ajaxType == 'add'">
            <Select v-model="addData.position" :transfer="true" style="width:100%;">
              <Option v-for="item in positionArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </FormItem>
          <FormItem label="身份">
            <Select v-model="addData.station" :transfer="true" style="width:100%;">
              <Option v-for="item in stationArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </FormItem>
          <FormItem label="手机号">
            <Input v-model="addData.mobile" placeholder="手机号"></Input>
          </FormItem>
          <FormItem label="办公电话">
            <Input v-model="addData.landline" placeholder="办公电话"></Input>
          </FormItem>
          <FormItem label="人员状态">
            <Select v-model="addData.status" :transfer="true" style="width:100%;">
              <Option v-for="item in statusArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </FormItem>
          <FormItem label="用户类型">
            <Select v-model="addData.userTypeId" :transfer="true" style="width:100%;">
              <Option v-for="item in userTypeArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </FormItem>
          <FormItem label="是否开通IM服务">
            <i-switch v-model="addData.openIM">
              <span slot="open">是</span>
              <span slot="close">否</span>
            </i-switch>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideAddModal">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="save()">确定</Button>
        </div>
      </Modal>
      <!--导入-->
      <Modal v-model="importDataModal" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">导入用户信息</h3>
        <Form label-position="top">
          <FormItem label="上传附件">
            <div class="dataDetail-div chooseUser accessory">
              <div class="users" v-for="el in importDataArr">
                <span class="span-name" v-text="el.name"></span>
                <span class="span-icon" @click="delimportData(el)">
                  <Icon type="md-close"/>
                </span>
              </div>
              <Upload v-if="importDataArr.length == 0"
                      :before-upload="handleUpload" action="">
                <Button icon="ios-cloud-upload-outline">选择文件</Button>
              </Upload>
            </div>
          </FormItem>
          <FormItem label="是否开通IM服务">
            <i-switch v-model="addData.openIM">
              <span slot="open">是</span>
              <span slot="close">否</span>
            </i-switch>
          </FormItem>
          <FormItem label="预览" v-if="ImportData.length > 0">
            <div class="dataDetail-div dataDetail-div-padding-0">
              <Table stripe border :columns="ImportDataColumns" :data="ImportData" height="360"></Table>
            </div>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideImportDataModal">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="saveImportData()">确定</Button>
        </div>
      </Modal>
      <!--调整部门列表-->
      <Modal v-model="showUpdateDepModal" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">所在部门</h3>
        <Form label-position="top">
          <FormItem label="">
            <div class="dataDetail-div dataDetail-div-padding-0">
              <Table stripe border :columns="UpdateDep_columns" :data="UpdateDepArr" height="330"></Table>
            </div>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideUpdateDep">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="addDeps()">添加</Button>
        </div>
      </Modal>
      <!--调整部门-->
      <Modal v-model="showUpdateAddDepModal" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">所在部门</h3>
        <Form label-position="top">
          <FormItem label="部门">
            <div class="dataDetail-div">
              <Tree :data="depTreeData" children-key="children" v-if="updateDepData.type == 'add'"
                    @on-select-change="depOnTree"></Tree>
              <span v-if="updateDepData.type != 'add'" v-text="updateDepData.dname"></span>
            </div>
          </FormItem>
          <FormItem label="岗位1">
            <div class="dataDetail-div">
              <Select v-model="updateDepData.pid" :transfer="true" style="width:100%;">
                <Option v-for="item in positionArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
              </Select>
            </div>
          </FormItem>
          <FormItem label="岗位2">
            <div class="dataDetail-div">
              <Select v-model="updateDepData.pid2" :transfer="true" style="width:100%;">
                <Option v-for="item in positionArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
              </Select>
            </div>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideAddDeps">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="saveDeps()">确定</Button>
        </div>
      </Modal>
      <!--新用户分配部门-->
      <Modal v-model="showNewUserAddDepModal" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">分配部门</h3>
        <Form label-position="top">
          <FormItem label="部门">
            <div class="dataDetail-div">
              <Tree :data="depTreeData" children-key="children" v-if="updateDepData.type == 'add'"
                    @on-select-change="depOnTree"></Tree>
              <span v-if="updateDepData.type != 'add'" v-text="updateDepData.dname"></span>
            </div>
          </FormItem>
          <FormItem label="岗位1">
            <div class="dataDetail-div">
              <Select v-model="updateDepData.pid" :transfer="true" style="width:100%;">
                <Option v-for="item in positionArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
              </Select>
            </div>
          </FormItem>
          <FormItem label="岗位2">
            <div class="dataDetail-div">
              <Select v-model="updateDepData.pid2" :transfer="true" style="width:100%;">
                <Option v-for="item in positionArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
              </Select>
            </div>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideNewUserAddDepModal">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="saveNewUserAddDep()">确定</Button>
        </div>
      </Modal>
      <!--审批列表-->
      <Modal v-model="showApprovalListModal" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">审批</h3>
        <Form label-position="top">
          <FormItem label="">
            <div class="dataDetail-div dataDetail-div-padding-0">
              <Table stripe border :columns="ApprovalList_columns" :data="ApprovalList"></Table>
            </div>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideApprovalList">取消</Button>
        </div>
      </Modal>
    </Row>
    <spin-page :showSpin="showSpin"></spin-page>
  </div>
</template>

<script>
  import Cookies from 'js-cookie';
  import Util from '../../libs/util';
  import Utils from '../../libs/mod.utils';
  import String from '../../libs/mod.string';
  import Modal from '../../libs/mod.Modal';
  import userAvatar from '../components/user-avatar.vue';
  import userInfo from '../components/user-info.vue';
  import spinPage from '../components/spin-page.vue';
  export default {
    components: {
      userAvatar,
      userInfo,
      spinPage
    },
    data () {
      return {
        TableHeight: 300,
        spanList: 18,
        showDetail: false,
        total: 0,
        page: 1,
        size: 10,
        order_by: [],
        id: '',
        depid: '',
        status: 2,//在职
        showCurrentTableData: false,
        columns: [
          {
            type: 'selection',
            width: 60,
            align: 'center'
          },
          {
            key: 'name',
            title: '姓名',
            width: 100,
            align: 'center',
            sortable: 'custom',
          },
          {
            key: 'mobile',
            title: '电话',
            align: 'center',
            sortable: 'custom',
          },
          {
            key: 'department_name',
            title: '部门',
            align: 'center',
            sortable: 'custom',
          },
          {
            key: 'position',
            title: '职务',
            align: 'center',
            sortable: 'custom',
            render: (h, params) => {
              var position = params.row.position || {};
              var position2 = params.row.position2 || {};
              var arr = [];
              if (position && position.title) {
                arr.push(position.title);
              }
              if (position2 && position2.title) {
                arr.push(position2.title);
              }
              var str = arr.join(' ， ');
              return h('div', [
                h('span', str)
              ]);
            }
          },
          {
            key: 'status',
            title: '在职状态',
            width: 120,
            align: 'center',
            sortable: 'custom',
            render: (h, params) => {
              return h('div', [
                h('span', params.row.status.title)
              ]);
            }
          },
        ],
        data: [],
        is_not_pass: false,
        data_not_pass: [],
        columns_not_pass: [
          {
            type: 'selection',
            width: 60,
            align: 'center'
          },
          {
            key: 'name',
            title: '姓名',
            width: 100,
          },
          {
            key: 'mobile',
            title: '电话',
          },
          {
            key: 'position',
            title: '申请部门',
            render: (h, params) => {
              var approval = params.row.approval || [];
              var arr = [];
              if (approval.length > 0) {
                for (var k in approval) {
                  if (!approval[k]) {
                    continue;
                  }
                  var str = approval[k].data;
                  if (str) {
                    var data = Util.toJson(str);
                    var dname = data.dname;
                    var pTitle = data.pTitle;
                    arr.push(dname + ':' + pTitle);
                  }
                }
              }
              var str = arr.join(' ， ');
              return h('div', [
                h('span', str)
              ]);
            }
          },
          {
            title: '操作',
            key: 'action',
            width: 150,
            align: 'center',
            render: (h, params) => {
              var Button1 = h('Button', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  marginRight: '5px'
                },
                on: {
                  click: e => {
                    e.stopPropagation();
                    var data = params.row;
                    this.showApprovalList(data);
                  }
                }
              }, '审批');
              var Button2 = h('Button', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  marginRight: '5px'
                },
                on: {
                  click: e => {
                    e.stopPropagation();
                    var data = params.row;
                    this.showNewUserAddDep(data);
                  }
                }
              }, '分配部门');
              var Button = '';
              if (this.depid == 'not_pass') {// 其他

              } else if (this.depid == 'registered') {// 已注册
                Button = Button2;
              } else if (this.depid == 'apply') {// 已申请
                Button = Button1;
              }
              return h('div', [
                Button
              ]);
            }
          }
        ],
        dataDetail: {},
        TreeData: [],
        userDetail: {
          id: '',
          username: '',
          avatar: '',
          name: '',
          mobile: '',
        },
        dataArr: [],
        buttonProps: {
          type: 'ghost',
          size: 'small',
        },
        saveLoading: false,
        dep: {
          pid: '',
          id: '',
          name: '',
          type: '',
          landline: '',
          showModal: false,
        },
        depTypeArr: [],
        addDepValidate: {
          name: [
            {required: true, message: '请输入部门名称', trigger: 'blur'}
          ],
        },
        depAjaxType: 'add',
        depTitle: '',
        addCurrentTableData: false,
        ajaxType: 'add',
        addData: {
          name: '',
          sex: '',
          position: '',
          station: '',
          status: '',
          userTypeId: '',
          mobile: '',
          landline: '',
          openIM: false,
        },
        selectionArr: [],
        statusArr: [],// 状态
        selectionArr_pass: [],
        checked_dep_arr: [],
        checked_users_arr: [],
        sexArr: [
          {
            name: '男',
            id: 'male'
          },
          {
            name: '女',
            id: 'female'
          }
        ],
        positionArr: [],
        stationArr: [],
        importDataModal: false,
        importDataArr: [],
        ImportDataColumns: [],
        ImportData: [],
        showUpdateDepModal: false,
        UpdateDepArr: [],
        UpdateDep_columns: [
          {
            key: 'name',
            title: '部门名称',
          },
          {
            key: 'type',
            title: '部门类型',
            width: 90,
            render: (h, params) => {
              var type = params.row.type;
              var title = type.title ? type.title : '';
              return h('div', [
                h('span', title)
              ]);
            }
          },
          {
            key: 'position',
            title: '岗位1',
            width: 80,
            render: (h, params) => {
              var position = params.row.position;
              var title = position[0] ? position[0].title : '';
              return h('div', [
                h('span', title)
              ]);
            }
          },
          {
            key: 'position',
            title: '岗位2',
            width: 80,
            render: (h, params) => {
              var position = params.row.position;
              var title = position[1] ? position[1].title : '';
              return h('div', [
                h('span', title)
              ]);
            }
          },
          {
            title: '操作',
            key: 'action',
            width: 150,
            align: 'center',
            render: (h, params) => {
              return h('div', [
                h('Button', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: e => {
                      e.stopPropagation();
                      var data = params.row;
                      this.updateDeps(data);
                    }
                  }
                }, '修改'),
                h('Button', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {},
                  on: {
                    click: e => {
                      e.stopPropagation();
                      var data = params.row;
                      this.removeDeps(data);
                    }
                  }
                }, '删除')
              ]);
            }
          }
        ],
        showUpdateAddDepModal: false,
        depTreeData: [],
        updateDepData: {
          type: 'add',
          did: '',
          dname: '',
          pid: '',
          pid2: '',
        },
        showNewUserAddDepModal: false,
        showApprovalListModal: false,
        ApprovalList: [],
        ApprovalList_columns: [
          {
            key: 'name',
            title: '姓名',
          },
          {
            key: 'mobile',
            title: '电话',
          },
          {
            key: 'dname',
            title: '申请部门',
          },
          {
            key: 'pTitle',
            title: '申请职务',
          },
          {
            title: '操作',
            key: 'action',
            width: 150,
            align: 'center',
            render: (h, params) => {
              return h('div', [
                h('Button', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: e => {
                      e.stopPropagation();
                      var data = params.row;
                      this.ApprovalPass(data);
                    }
                  }
                }, '通过')
              ]);
            }
          }
        ],
        search_name: '',
        userInfo_id: '',// 查看用户详情的用户id
        showSpin: false,//加载中
        userTypeArr: [],// 用户类型
      };
    },
    computed: {},
    mounted () {
      var _this = this;
      _this.getTreeData();
      _this.getPositionArr();
      _this.getStationArr();
      _this.getStatusArr();
      _this.getUserTypeArr();
      _this.$nextTick(function () {
        var height = $('#TableCard').height();
        var TableHeight = height - 36 - 32 - 10 - 56 - 51;
        _this.TableHeight = TableHeight;
      });
    },
    methods: {
      // 排序
      onSortChange: function (data) {
        var _this = this;
        var column = data.column;
        var key = data.key;
        switch (key) {
          case 'position' :
            key = 'position.title';
            break;
          case 'status' :
            key = 'status.title';
            break;
          case 'name' :
            key = 'CONVERT(u.name USING gbk)';
            break;
        }
        var order = data.order;
        if (order == 'asc' || order == 'desc') {
          var orderObj = {
            field: key,
            sort: order,
          };
          _this.order_by = [orderObj];
          _this.getData();
        } else {
          _this.order_by = [];
          _this.getData();
        }
      },
      // 取消列表选中
      hideNums: function () {
        var _this = this;
        if (_this.is_not_pass == true) {
          _this.$refs.selectionTable_not_pass.selectAll(false);
        } else {
          _this.$refs.selectionTable.selectAll(false);
        }
        _this.selectionArr = [];
        _this.selectionArr_pass = [];
      },
      // 列表上修改
      updateFun: function (type) {
        var _this = this;
        var selectionArr = _this.selectionArr;
        if (selectionArr.length == 0) {
          _this.$Message.destroy();
          _this.$Message.error('请选择要修改的数据!');
          return false;
        }
        if (selectionArr.length > 1) {
          _this.$Message.destroy();
          _this.$Message.error('一次只能修改一条数据!');
          return false;
        }
        var data = selectionArr[0];
        if (type == 'updateDep') {
          _this.showUpdateDep(data);
        } else if (type == 'update') {
          _this.updateUser(data);
        }
      },
      // 搜索
      searchFun: function () {
        var _this = this;
        _this.selectionArr = [];
        _this.page = 1;
        if (_this.search_name != '') {
          _this.depid = '';
          _this.depTitle = '';
        }
        _this.getData();
      },
      changePage (page) {
        var _this = this;
        if (_this.depid == 'not_pass') {// 其他

        } else if (_this.depid == 'registered') {// 已注册
          _this.is_not_pass = true;
          _this.selectionArr = [];
          _this.page = page;
          _this.get_not_pass();
        } else if (_this.depid == 'apply') {// 已申请
          _this.is_not_pass = true;
          _this.selectionArr = [];
          _this.page = page;
          _this.get_not_pass();
        } else {// 正常用户
          _this.is_not_pass = false;
          _this.selectionArr = [];
          _this.page = page;
          _this.getData();
        }
      },
      getTreeData: function () {
        var _this = this;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
        };
        var params = {
          url: '/department/list',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var data = res.data || [];

            var dataArr = data;
            _this.dataArrFun(dataArr);

            if (data.length > 0) {
              data[0].selected = true;
              var iid = data[0].id;
              var depTitle = data[0].name;
              _this.depid = iid;
              _this.getData();
              _this.depTitle = depTitle;
            }
            var obj = {
              id: 'not_pass',
              name: '其他',
              title: '其他',
              expand: true,
              children: [
                {
                  id: 'registered',
                  name: '已注册',
                  title: '已注册',
                },
                {
                  id: 'apply',
                  name: '已申请',
                  title: '已申请',
                },
                {
                  id: 'departure',
                  name: '已离职',
                  title: '已离职',
                }
              ],
            };
            data.push(obj);
            _this.TreeData = data;
          } else {
            _this.$Message.destroy();
            _this.$Message.error('查询部门信息失败!');
          }
        }
      },
      dataArrFun: function (arr) {
        var _this = this;
        if (arr.length > 0) {
          for (var k in arr) {
            if (!arr[k]) {
              continue;
            }
            arr[k].title = arr[k].name;
            arr[k].expand = true;
            var dataArr = arr[k].children;
            _this.dataArrFun(dataArr);
          }
        }
      },
      onTree: function (data) {
        var _this = this;
        var id = data.id;
        var title = data.title;
        if (id) {
          _this.search_name = '';// 清空搜索框
          if (id == 'not_pass') {// 其他

          } else if (id == 'registered') {// 已注册
            _this.is_not_pass = true;
            _this.selectionArr = [];
            _this.depid = id;
            _this.depTitle = title;
            _this.page = 1;
            _this.get_not_pass();
          } else if (id == 'apply') {// 已申请
            _this.is_not_pass = true;
            _this.selectionArr = [];
            _this.depid = id;
            _this.depTitle = title;
            _this.page = 1;
            _this.get_not_pass();
          } else if (id == 'departure') {// 已离职
            _this.is_not_pass = false;
            _this.selectionArr = [];
            _this.depid = '';
            _this.depTitle = title;
            _this.page = 1;
            _this.status = 3;//已离职
            _this.getData();
          } else {// 正常用户
            _this.is_not_pass = false;
            _this.selectionArr = [];
            _this.depid = id;
            _this.depTitle = title;
            _this.page = 1;
            _this.status = 2;//在职
            _this.getData();
          }
        }
      },
      getData: function () {
        var _this = this;
        _this.showDetail = false;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          did: _this.depid,
          status: _this.status,
          page: _this.page,
          size: _this.size,
          name: _this.search_name,
          order_by: _this.order_by,
        };
        var params = {
          url: '/user/list1',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.showSpin = true;
        function _successFun(res) {
          _this.showSpin = false;
          if (res.result == 0) {
            var data = res.data || [];
            _this.total = res.rows || 0;
            _this.data = data;
            _this.hideNums();
          } else {
            _this.$Message.destroy();
            _this.$Message.error('查询人员信息失败!');
          }
        }
      },
      // 未通过人员
      get_not_pass: function () {
        var _this = this;
        _this.showDetail = false;
        var type = '';
        if (_this.depid == 'registered') {// 已注册
          type = 'onlyRegister';
        } else if (_this.depid == 'apply') {// 已申请
          type = 'notOnlyRegister';
        }
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          page: _this.page,
          size: _this.size,
          type: type,
        };
        var params = {
          url: '/user/list1',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.showSpin = true;
        function _successFun(res) {
          _this.showSpin = false;
          if (res.result == 0) {
            var data = res.data || [];
            _this.total = res.rows || 0;
            _this.data_not_pass = data;
          } else {
            _this.$Message.destroy();
            _this.$Message.error('查询人员信息失败!');
          }
        }
      },
      onRowData: function (data, index) {
        var _this = this;
        var id = data.id;
        _this.id = id;
        _this.userInfo_id = id;
      },
      userInfoBackFun: function (id) {
        var _this = this;
        _this.userInfo_id = id;
      },
      heid_userInfo: function () {
        var _this = this;
        _this.showDetail = false;
      },
      renderContent (h, {root, node, data}) {
        var _this = this;
        var nodeKey = node.nodeKey;
        var add = h('Button', {
          props: Object.assign({}, this.buttonProps, {
            icon: 'ios-add',
            type: 'default'
          }),
          style: {
            marginRight: '4px'
          },
          on: {
            click: e => {
              e.stopPropagation();
              this.append(data)
            }
          }
        });
        var update = h('Button', {
          props: Object.assign({}, this.buttonProps, {
            icon: 'ios-create-outline',
            type: 'default'
          }),
          style: {
            marginRight: '4px'
          },
          on: {
            click: e => {
              e.stopPropagation();
              this.update(data)
            }
          }
        });
        var del = h('Button', {
          props: Object.assign({}, this.buttonProps, {
            icon: 'ios-remove',
            type: 'default'
          }),
          on: {
            click: e => {
              e.stopPropagation();
              this.remove(root, node, data)
            }
          }
        });
        var marginRight = '16px';
        var ButtonArr = [];
        ButtonArr.push(add);
        ButtonArr.push(update);
        if (nodeKey > 0) {
          ButtonArr.push(del);
        } else {
          marginRight = '38px';
        }
        if (data.id == 'not_pass' || data.id == 'registered' || data.id == 'apply' || data.id == 'departure') {// 未通过人员
          ButtonArr = [];
        }

        return h('span', {
          style: {
            display: 'inline-block',
            width: '100%',
            cursor: 'pointer'
          },
          on: {
            click: () => {
              _this.onTree(data);
            }
          }
        }, [
          h('span', [
            /*h('Icon', {
             props: {
             type: 'ios-paper-outline'
             },
             style: {
             marginRight: '8px'
             }
             }),*/
            h('span', data.title)
          ]),
          h('span', {
              style: {
                display: 'inline-block',
                float: 'right',
                marginRight: marginRight
              }
            },
            ButtonArr
          )
        ]);
      },
      getdepTreeData: function () {
        var _this = this;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          //type: 'parent',
          //id: -1
        };
        var params = {
          url: '/department/list',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var data = res.data || [];

            var dataArr = data;
            _this.depdataArrFun(dataArr);

            _this.depTreeData = data;
          } else {
            _this.$Message.destroy();
            _this.$Message.error('查询部门信息失败!');
          }
        }
      },
      depdataArrFun: function (arr) {
        var _this = this;
        if (arr.length > 0) {
          for (var k in arr) {
            if (!arr[k]) {
              continue;
            }
            arr[k].title = arr[k].name;
            //arr[k].expand = true;
            var dataArr = arr[k].children;
            _this.depdataArrFun(dataArr);
          }
        }
      },
      depOnTree: function (data) {
        var _this = this;
        _this.updateDepData.did = '';
        if (data.length > 0) {
          _this.updateDepData.did = data[0].id;
        }
      },
      // 获取部门类型
      getDepTypeArr: function () {
        var _this = this;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
        };
        var params = {
          url: '/department/type/list',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var data = res.data || [];
            var depTypeArr = [];
            for (var k in data) {
              if (!data[k]) {
                continue;
              }
              var id = data[k].id;
              var title = data[k].title;
              var obj = {
                id: id,
                name: title
              };
              depTypeArr.push(obj);
            }
            _this.depTypeArr = depTypeArr;
          } else {
            _this.$Message.destroy();
            _this.$Message.error('查询部门信息失败!');
          }
        }
      },
      // 获取岗位
      getPositionArr: function () {
        var _this = this;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
        };
        var params = {
          url: '/department/position/list',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var data = res.data || [];
            var positionArr = [];
            for (var k in data) {
              if (!data[k]) {
                continue;
              }
              var id = data[k].id;
              var title = data[k].title;
              var obj = {
                id: id,
                name: title
              };
              positionArr.push(obj);
            }
            _this.positionArr = positionArr;
          } else {
            _this.$Message.destroy();
            _this.$Message.error('查询岗位信息失败!');
          }
        }
      },
      // 获取身份
      getStationArr: function () {
        var _this = this;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
        };
        var params = {
          url: '/user/station/list',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var data = res.data || [];
            var stationArr = [];
            for (var k in data) {
              if (!data[k]) {
                continue;
              }
              var id = data[k].id;
              var title = data[k].title;
              var obj = {
                id: id,
                name: title
              };
              stationArr.push(obj);
            }
            _this.stationArr = stationArr;
          } else {
            _this.$Message.destroy();
            _this.$Message.error('查询身份信息失败!');
          }
        }
      },
      // 获取状态
      getStatusArr: function () {
        var _this = this;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
        };
        var params = {
          url: '/user/status/list',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var data = res.data || [];
            var statusArr = [];
            for (var k in data) {
              if (!data[k] || data[k].id == 1) { // 去掉 注册
                continue;
              }
              var id = data[k].id;
              var title = data[k].title;
              var obj = {
                id: id,
                name: title
              };
              statusArr.push(obj);
            }
            _this.statusArr = statusArr;
          } else {
            _this.$Message.destroy();
            _this.$Message.error('查询身份信息失败!');
          }
        }
      },
      // 获取用户类型
      getUserTypeArr: function () {
        var _this = this;
        var data = {};
        var params = {
          url: '/user/type/list',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var data = res.data || [];
            var userTypeArr = [];
            for (var k in data) {
              if (!data[k]) {
                continue;
              }
              var id = data[k].id;
              var title = data[k].title;
              var obj = {
                id: id,
                name: title
              };
              userTypeArr.push(obj);
            }
            _this.userTypeArr = userTypeArr;
          } else {
            _this.$Message.destroy();
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      // 添加部门
      append (data) {
        var _this = this;
        _this.getDepTypeArr();
        _this.dep.type = '';
        var pid = data.id;
        _this.depAjaxType = 'add';
        _this.dep.pid = pid;
        _this.dep.showModal = true;
      },
      // 删除部门
      remove (root, node, data) {
        var _this = this;
        var id = data.id;
        var name = data.name;
        var content = '确定删除' + name + '，及子部门？';
        Modal.confirm(_this, {content: content}, function () {
          _this.delDep(id);
        }, function () {
        });
      },
      // 修改部门
      update: function (data) {
        var _this = this;
        _this.getDepTypeArr();
        _this.depAjaxType = 'update';
        var id = data.id;
        _this.dep.id = id;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          id: id
        };
        var params = {
          url: '/department/query',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.dep.type = _data.type ? _data.type.id : '';
            _this.dep.pid = _data.pid;
            _this.dep.name = _data.name;
            _this.dep.landline = _data.landline;
            _this.dep.showModal = true;
          } else {
            _this.$Message.destroy();
            _this.$Message.error('查询部门信息失败!');
          }
        }
      },
      // 删除部门
      delDep: function (id) {
        var _this = this;
        if (!id) {
          return false;
        }
        var ids = [];
        ids.push(id);
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          id: ids,
        };
        var params = {
          url: '/department/delete',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            _this.$Message.destroy();
            _this.$Message.success('删除部门信息成功!');
            _this.getTreeData();
          } else {
            _this.$Message.destroy();
            _this.$Message.error('删除部门信息失败!');
          }
        }
      },
      // 关闭编辑部门
      cancelDepMobile: function () {
        var _this = this;
        _this.dep.name = '';
        _this.dep.landline = '';
        _this.dep.showModal = false;
      },
      // 保存部门信息
      saveDep: function () {
        var _this = this;
        var pid = _this.dep.pid;
        var type = _this.dep.type;
        var name = _this.dep.name;
        var landline = _this.dep.landline;
        if (type == '') {
          _this.$Message.destroy();
          _this.$Message.error('请选择部门类型!');
          return false;
        }
        if (name == '') {
          _this.$Message.destroy();
          _this.$Message.error('请输入部门名称!');
          return false;
        }
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          pid: pid,
          type: type,
          name: name,
          landline: landline,
        };
        var url = '/department/add';
        if (_this.depAjaxType == 'update') {
          url = '/department/update';
          data = {
            action: 'name',
            id: _this.dep.id,
            uid: Util.toJson(localStorage.getItem('userInfo')).id,
            type: type,
            name: name,
            pid: pid,
            landline: landline
          };
        }
        var params = {
          url: url,
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.saveLoading = true;
        function _successFun(res) {
          _this.saveLoading = false;
          if (res.result == 0) {
            var data = res.data || [];

            _this.getTreeData();
            _this.dep.id = '';
            _this.dep.pid = '';
            _this.dep.name = '';
            _this.dep.landline = '';
            _this.dep.showModal = false;
          } else {
            _this.$Message.destroy();
            _this.$Message.error('保存部门信息失败!');
          }
        }

      },
      // 列表多选 选中数据
      selectionChange: function (selection) {
        var _this = this;
        _this.selectionArr = selection;
      },
      selectionChange_pass: function (selection) {
        var _this = this;
        _this.selectionArr_pass = selection;
      },
      // 隐藏编辑页面
      hideAddModal: function () {
        var _this = this;
        _this.addCurrentTableData = false;
      },
      // 显示添加界面
      addUser: function () {
        var _this = this;
        _this.addData.name = '';
        _this.addData.sex = '';
        _this.addData.position = '';
        _this.addData.station = '';
        _this.addData.status = '';
        _this.addData.userTypeId = '';
        _this.addData.mobile = '';
        _this.addData.landline = '';
        _this.addData.openIM = false;
        _this.ajaxType = 'add';
        _this.addCurrentTableData = true;
      },
      // 保存数据
      save: function () {
        var _this = this;
        var name = _this.addData.name;
        var sex = _this.addData.sex;
        var position = _this.addData.position;
        var station = _this.addData.station;
        var status = _this.addData.status;
        var userTypeId = _this.addData.userTypeId;
        var mobile = _this.addData.mobile;
        var landline = _this.addData.landline;
        var openIM = _this.addData.openIM;
        if (!(name && name != '')) {
          _this.$Message.destroy();
          _this.$Message.error('请填写姓名!');
          return false;
        }
        if (sex == '') {
          _this.$Message.destroy();
          _this.$Message.error('请选择性别!');
          return false;
        }
        if (station == '') {
          _this.$Message.destroy();
          _this.$Message.error('请选择身份!');
          return false;
        }
        if (mobile == '') {
          _this.$Message.destroy();
          _this.$Message.error('请填写手机号!');
          return false;
        }
        var data = {
          id: _this.id,
          type: 'type-in',
          name: name,
          mobile: mobile,
          sex: sex,
          pid: position,
          did: _this.depid,
          landline: landline,
          station: station,
          status: status,
          userType: userTypeId,
          NTStatus: openIM == true ? 'true' : 'false',
        };
        var url = '/user/add';
        if (_this.ajaxType == 'update') {
          url = '/user/update';
        }
        var params = {
          url: url,
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.saveLoading = true;
        function _successFun(res) {
          _this.saveLoading = false;
          if (res.result == 0) {
            _this.page = 1;
            _this.getData();
            _this.addCurrentTableData = false;
            _this.addData.name = '';
            _this.addData.sex = '';
            _this.addData.position = '';
            _this.addData.station = '';
            _this.addData.status = '';
            _this.addData.userTypeId = '';
            _this.addData.mobile = '';
            _this.addData.landline = '';
          } else {
            _this.$Message.destroy();
            _this.$Message.error('保存信息失败!');
          }
        }
      },
      // 显示修改界面
      updateUser: function (data, index) {
        var _this = this;
        _this.ajaxType = 'update';
        var id = data.id;
        _this.id = id;
        var data = {
          id: _this.id,
        };
        var params = {
          url: '/user/query',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            var position = '';
            var depid = _this.depid;
            var departments = _data.departments;
            for (var k in departments) {
              if (!departments[k]) {
                continue;
              }
              if (departments[k].id == depid) {
                var positionArr = departments[k].position;
                if (positionArr.length > 0) {
                  position = positionArr[0].id;
                }
                break;
              }
            }
            _this.addData.name = _data.name;
            _this.addData.sex = _data.sex;
            _this.addData.position = position;
            _this.addData.station = _data.station && _data.station.id ? _data.station.id : '';
            _this.addData.status = _data.status && _data.status.id ? _data.status.id : '';
            _this.addData.userTypeId = _data.type && _data.type.id ? _data.type.id : '';
            _this.addData.mobile = _data.mobile;
            _this.addData.landline = _data.landline;
            _this.addData.openIM = _data.nim_token == 1 ? true : false;
            _this.addCurrentTableData = true;
          } else {
            _this.$Message.destroy();
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      // 隐藏分配部门
      hideNewUserAddDepModal: function () {
        var _this = this;
        _this.updateDepData.did = '';
        _this.updateDepData.dname = '';
        _this.updateDepData.pid = '';
        _this.updateDepData.pid2 = '';
        _this.showNewUserAddDepModal = false;
      },
      // 显示分配部门
      showNewUserAddDep: function (data) {
        var _this = this;
        var id = data.id;
        _this.id = id;
        _this.updateDepData.type = 'add';
        _this.getdepTreeData();
        _this.getPositionArr();
        _this.updateDepData.did = '';
        _this.updateDepData.dname = '';
        _this.updateDepData.pid = '';
        _this.updateDepData.pid2 = '';
        _this.showNewUserAddDepModal = true;
      },
      // 保存 分配部门
      saveNewUserAddDep: function () {
        var _this = this;
        var type = _this.updateDepData.type;
        var did = _this.updateDepData.did;
        var pid = _this.updateDepData.pid;
        var pid2 = _this.updateDepData.pid2;
        if (did == '') {
          _this.$Message.destroy();
          _this.$Message.error('请选择部门!');
          return false;
        }
        if (pid == '' && pid2 == '') {
          _this.$Message.destroy();
          _this.$Message.error('请选择岗位!');
          return false;
        }
        var data = {
          action: 'add',
          id: did,
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          staff: [{
            did: did,
            uid: _this.id,
            pid: pid == '' ? -1 : pid,
            pid2: pid2 == '' ? -1 : pid2
          }]
        };
        var params = {
          url: '/department/adjust',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            _this.updateUserstatus();
          } else {
            _this.$Message.destroy();
            _this.$Message.error('保存信息失败!');
          }
        }
      },
      // 修改用户状态，生成tokey
      updateUserstatus: function () {
        var _this = this;
        var data = {
          id: _this.id,
          status: 2,
        };
        var params = {
          url: '/user/update',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            _this.get_not_pass();
            _this.hideNewUserAddDepModal();
          } else {
            _this.$Message.destroy();
            _this.$Message.error('保存信息失败!');
          }
        }
      },
      // 显示审批列表
      showApprovalList: function (_data) {
        var _this = this;
        var ApprovalList = [];
        var name = _data.name;
        var mobile = _data.mobile;
        var approval = _data.approval;
        for (var k in approval) {
          if (!approval[k]) {
            continue;
          }
          var id = approval[k].id;
          var title = approval[k].title;
          var content = approval[k].content;
          var dataStr = approval[k].data;
          if (dataStr) {
            var dataObj = Util.toJson(dataStr);
            var dname = dataObj.dname;
            var pTitle = dataObj.pTitle;
            var obj = {
              id: id,
              name: name,
              mobile: mobile,
              title: title,
              content: content,
              dname: dname,
              pTitle: pTitle,
            };
            ApprovalList.push(obj);
          }
        }
        _this.ApprovalList = ApprovalList;
        _this.showApprovalListModal = true;
      },
      // 隐藏审批列表
      hideApprovalList: function () {
        var _this = this;
        _this.showApprovalListModal = false;
      },
      // 审批通过
      ApprovalPass: function (_data) {
        var _this = this;
        var data = {
          id: _data.id,
          pass: true,
        };
        var params = {
          url: '/approval/personnelUpdate',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            _this.get_not_pass();
            _this.hideApprovalList();
            _this.$Message.destroy();
            _this.$Message.success('审核成功!');
          } else {
            _this.$Message.destroy();
            _this.$Message.error('审核失败!');
          }
        }
      },
      // 隐藏调整部门列表
      hideUpdateDep: function (data) {
        var _this = this;
        _this.showUpdateDepModal = false;
      },
      // 显示调整部门列表
      showUpdateDep: function (data) {
        var _this = this;
        if (data) {
          var id = data.id;
          _this.id = id;
        }
        var data = {
          id: _this.id,
        };
        var params = {
          url: '/user/query',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            var departments = _data.departments;
            _this.UpdateDepArr = departments;
            _this.showUpdateDepModal = true;
          } else {
            _this.$Message.destroy();
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      // 添加所在部门
      addDeps: function () {
        var _this = this;
        _this.updateDepData.type = 'add';
        _this.getdepTreeData();
        _this.getPositionArr();
        _this.updateDepData.did = '';
        _this.updateDepData.dname = '';
        _this.updateDepData.pid = '';
        _this.updateDepData.pid2 = '';
        _this.showUpdateAddDepModal = true;
        _this.showUpdateDepModal = false;
      },
      // 修改所在部门
      updateDeps: function (data) {
        var _this = this;
        _this.updateDepData.type = 'update';
        _this.getPositionArr();

        var pid = '';
        var pid2 = '';
        var position = data.position;
        if (position && position[0] && position[0].id) {
          pid = position[0].id;
        }
        if (position && position[1] && position[1].id) {
          pid2 = position[1].id;
        }
        _this.updateDepData.did = data.id;
        _this.updateDepData.dname = data.name;
        _this.updateDepData.pid = pid;
        _this.updateDepData.pid2 = pid2;

        _this.showUpdateAddDepModal = true;
        _this.showUpdateDepModal = false;
      },
      // 保存
      saveDeps: function () {
        var _this = this;
        var type = _this.updateDepData.type;
        var did = _this.updateDepData.did;
        var pid = _this.updateDepData.pid;
        var pid2 = _this.updateDepData.pid2;
        if (did == '') {
          _this.$Message.destroy();
          _this.$Message.error('请选择部门!');
          return false;
        }
        if (pid == '' && pid2 == '') {
          _this.$Message.destroy();
          _this.$Message.error('请选择岗位!');
          return false;
        }
        var action = 'add';
        if (type == 'update') {
          action = 'update';
        }
        var data = {
          action: action,
          id: did,
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          staff: [{
            did: did,
            uid: _this.id,
            pid: pid == '' ? -1 : pid,
            pid2: pid2 == '' ? -1 : pid2
          }]
        };
        var params = {
          url: '/department/adjust',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            _this.hideAddDeps();
          } else {
            _this.$Message.destroy();
            _this.$Message.error('保存信息失败!');
          }
        }
      },
      // 隐藏编辑所在部门
      hideAddDeps: function () {
        var _this = this;
        _this.showUpdateAddDepModal = false;
        _this.showUpdateDep();
      },
      // 删除所在部门
      removeDeps: function (depSel) {
        var _this = this;
        Modal.confirm(_this, {content: '确定删除选中的信息？'}, function () {
          var data = {
            action: 'remove',
            id: depSel.id,
            uid: Util.toJson(localStorage.getItem('userInfo')).id,
            staff: [{
              did: depSel.id,
              uid: _this.id,
              pid: (depSel.position[0].id && depSel.position[0].id != null) ? depSel.position[0].id : -1,
              pid2: (depSel.position[1].id && depSel.position[1].id != null) ? depSel.position[1].id : -1
            }]
          };
          var params = {
            url: '/department/adjust',
            type: Util.method.post,
            data: data,
            success: _successFun
          };
          Util.ajax(_this, params);
          function _successFun(res) {
            if (res.result == 0) {
              _this.showUpdateDep();
            } else {
              _this.$Message.destroy();
              _this.$Message.error('删除信息失败!');
            }
          }
        }, function () {
        });
      },
      // 删除
      removeUser: function () {
        var _this = this;
        var selectionArr = _this.selectionArr;
        if (selectionArr.length == 0) {
          _this.$Message.destroy();
          _this.$Message.error('请选择要删除的数据!');
          return false;
        }
        var selectionIds = [];
        for (var k in selectionArr) {
          if (!selectionArr[k]) {
            continue;
          }
          var id = selectionArr[k].id;
          selectionIds.push(id);
        }
        Modal.confirm(_this, {content: '确定删除选中的信息？'}, function () {
          var data = {
            id: selectionIds,
          };
          var params = {
            url: '/user/delete',
            type: Util.method.post,
            data: data,
            success: _successFun
          };
          Util.ajax(_this, params);
          function _successFun(res) {
            if (res.result == 0) {
              _this.page = 1;
              if (_this.depid == 'not_pass') {// 其他

              } else if (_this.depid == 'registered') {// 已注册
                _this.get_not_pass();
              } else if (_this.depid == 'apply') {// 已申请
                _this.get_not_pass();
              } else {// 正常用户
                _this.getData();
              }
            } else {
              _this.$Message.destroy();
              _this.$Message.error('删除信息失败!');
            }
          }
        }, function () {
        });
      },
      // 导出
      ExportData: function () {
        var _this = this;
        var fields = [
          {
            field: 'uname',
            title: '姓名',
            type: 'varchar',
            order: 1,
          },
          {
            field: 'mobile',
            title: '电话',
            type: 'varchar',
            order: 2,
          },
          {
            field: 'sex',
            title: '性别',
            type: 'varchar',
            order: 3,
          },
          {
            field: 'department_name',
            title: '部门',
            type: 'varchar',
            order: 4,
          },
          {
            field: 'pname',
            title: '上级部门',
            type: 'varchar',
            order: 5,
          },
          {
            field: 'position',
            title: '岗位1',
            type: 'varchar',
            order: 6,
          },
          {
            field: 'position2',
            title: '岗位2',
            type: 'varchar',
            order: 7,
          },
          {
            field: 'status',
            title: '身份',
            type: 'varchar',
            order: 8,
          },
          {
            field: 'idcard',
            title: '身份证号',
            type: 'varchar',
            order: 9,
          },
          {
            field: 'status',
            title: '在职状态',
            type: 'varchar',
            order: 10,
          },
        ];
        var selectionArr = _this.selectionArr;
        if (selectionArr.length == 0) {
          selectionArr = _this.data;
        }
        var selectionIds = [];
        for (var k in selectionArr) {
          if (!selectionArr[k]) {
            continue;
          }
          var id = selectionArr[k].id;
          selectionIds.push(id);
        }

        var fieldsStr = Util.toStr(fields);
        var data = {};
        if (selectionIds.length > 0 && selectionIds.length == _this.data.length) { // 全选了
          Modal.confirm(_this, {content: '确定要导出全部信息？'}, function () {
            selectionIds = [];
            data = {
              uid: Util.toJson(localStorage.getItem('userInfo')).id,
              type: 'departmentUser',
              fields: fieldsStr,
            };
            _getAjax();
          }, function () {
            data = {
              uid: Util.toJson(localStorage.getItem('userInfo')).id,
              type: 'departmentUser',
              fields: fieldsStr,
              ids: selectionIds,
            };
            _getAjax();
          });
        } else {
          data = {
            uid: Util.toJson(localStorage.getItem('userInfo')).id,
            type: 'departmentUser',
            fields: fieldsStr,
            ids: selectionIds,
          };
          _getAjax();
        }
        function _getAjax() {
          var params = {
            url: '/attach/db2excle',
            type: Util.method.post,
            data: data,
            success: _successFun
          };
          Util.ajax(_this, params);
          _this.showSpin = true;
        }

        function _successFun(res) {
          _this.showSpin = false;
          if (res.result == 0) {
            var url = res.data;
            var date = Utils.dateToDateString(new Date());
            Utils.DownloadFile(url, '导出人员信息_' + date + '.xlsx');
          } else {
            _this.$Message.destroy();
            _this.$Message.error('导出信息失败!');
          }
        }
      },
      // 导入
      importData: function () {
        var _this = this;
        _this.importDataArr = [];
        _this.ImportDataColumns = [];
        _this.ImportData = [];
        _this.addData.openIM = false;
        _this.importDataModal = true;
      },
      // 取消导入
      hideImportDataModal: function () {
        var _this = this;
        _this.importDataArr = [];
        _this.ImportDataColumns = [];
        _this.ImportData = [];
        _this.importDataModal = false;
      },
      // 确定导入
      saveImportData: function () {
        var _this = this;
        if (_this.importDataArr.length == 0) {
          _this.$Message.destroy();
          _this.$Message.error('请上传附件!');
          return false;
        }
        var openIM = _this.addData.openIM;
        var file_id = _this.importDataArr[0].id;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          fid: file_id,
          NTStatus: openIM,
        };
        var params = {
          url: '/department/importExcel',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            _this.page = 1;
            _this.getTreeData();
            _this.hideImportDataModal();
          } else {
            _this.$Message.destroy();
            _this.$Message.error('导入信息失败!');
          }
        }
      },
      // 选中文件
      handleUpload: function (file) {
        var _this = this;
        _this.UploadFile(file);
        return false;
      },
      // 上传文件
      UploadFile: function (file) {
        var _this = this;
        var name = file.name;
        var arr = name.split('.');
        var type = arr[1];
        if (type != 'xlsx') {
          _this.$Message.destroy();
          _this.$Message.error('请上传xlsx文件!');
          return false;
        }
        var formData = new FormData();
        formData.append("file", file);
        formData.append("action", "UploadVMKImagePath");
        var params = {
          url: '/attach/addFile',
          type: Util.method.post,
          data: formData,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var data = res.data;
            var id = data.id;
            var name = data.name;
            var url = data.url;
            var obj = {
              id: id,
              name: name,
              url: url,
            };
            _this.importDataArr.push(obj);
            _this.getImportData(id);// 预览
          } else {
            _this.$Message.destroy();
            _this.$Message.error('上传失败!');
          }
        }
      },
      // 删除附件
      delimportData: function (el) {
        var _this = this;
        var id = el.id;
        var importDataArr = _this.importDataArr;
        for (var k in importDataArr) {
          if (!importDataArr[k]) {
            continue;
          }
          if (id == importDataArr[k].id) {
            var del = importDataArr.splice(k, 1);
            break;
          }
        }
        _this.importDataArr = importDataArr;
        _this.ImportDataColumns = [];
        _this.ImportData = [];
      },
      // 预览数据
      getImportData: function (file_id) {
        var _this = this;
        if (!file_id) {
          return;
        }
        var data = {
          fid: file_id,
          lines: 10,
        };
        var params = {
          url: '/attach/exclePreview',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data;
            var ImportDataColumns = [];
            var ImportData = [];
            if (_data.length > 0) {
              var Sheet1_data = _data[0].data;
              if (Sheet1_data.length > 0) {
                // 表头
                var titleArr = Sheet1_data[0];
                for (var t in titleArr) {
                  if (!titleArr[t]) {
                    continue;
                  }
                  var col = titleArr[t].col;
                  var title = titleArr[t].title;
                  var Columns = {
                    key: 'key_' + title + '_' + col,
                    title: title,
                    width: 150,
                  };
                  ImportDataColumns.push(Columns);
                }
                // 数据
                for (var k in Sheet1_data) {
                  if (!Sheet1_data[k]) {
                    continue;
                  }
                  var dataObj = {};
                  var dataArr = Sheet1_data[k];
                  for (var r in dataArr) {
                    if (!dataArr[r]) {
                      continue;
                    }
                    var col = dataArr[r].col;
                    var title = dataArr[r].title;
                    var value = dataArr[r].value;
                    var key = 'key_' + title + '_' + col;
                    dataObj[key] = value;
                  }
                  if (Object.keys(dataObj).length > 0) {
                    ImportData.push(dataObj);
                  }
                }
              }
            }
            _this.ImportDataColumns = ImportDataColumns;
            _this.ImportData = ImportData;
          } else {
            _this.$Message.destroy();
            _this.$Message.error('预览信息失败!');
          }
        }
      },
    }
  };
</script>

<style>

</style>
